package com.livecooking;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListMenuAdapter extends ArrayAdapter<String> {

	public Context myContext;
	public String[] mMenuOption;

	public ListMenuAdapter(Context context, String[] mMenuOption) {
		super(context, R.layout.listitem_type, mMenuOption);
		this.myContext = context;
		this.mMenuOption = mMenuOption;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		View rowView = convertView;
		ViewHolder viewHolder = null;
		// List<Integer> imageList = getAllImage(foodIdList);

		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) myContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.listitem_type, null);

			viewHolder = new ViewHolder();
			viewHolder.text = (TextView) rowView.findViewById(R.id.txtMenu);
			viewHolder.image = (ImageView) rowView.findViewById(R.id.imvMenu);

			rowView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.text.setText(mMenuOption[position]);
		String s = mMenuOption[position];

		if (s.equalsIgnoreCase("Tất cả")) {
			viewHolder.image.setImageResource(R.drawable.all);
		} else if (s.equalsIgnoreCase("Bánh")) {
			viewHolder.image.setImageResource(R.drawable.banh);
		} else if (s.equalsIgnoreCase("Luộc")) {
			viewHolder.image.setImageResource(R.drawable.luoc);
		} else if (s.equalsIgnoreCase("Rán")) {
			viewHolder.image.setImageResource(R.drawable.ran);
		} else if (s.equalsIgnoreCase("Xào")) {
			viewHolder.image.setImageResource(R.drawable.xao);
		} else if (s.equalsIgnoreCase("Kho")) {
			viewHolder.image.setImageResource(R.drawable.kho);
		} else if (s.equalsIgnoreCase("Canh")) {
			viewHolder.image.setImageResource(R.drawable.canh);
		} else if (s.equalsIgnoreCase("Nướng")) {
			viewHolder.image.setImageResource(R.drawable.nuong);
		} else if (s.equalsIgnoreCase("Nộm")) {
			viewHolder.image.setImageResource(R.drawable.nom);
		} else if (s.equalsIgnoreCase("Khác")) {
			viewHolder.image.setImageResource(R.drawable.other);
		} else {
			viewHolder.image.setImageResource(R.drawable.bookmark);
		}
		return rowView;
	}

	 @Override
	 public int getCount() {
	 return mMenuOption.length;
	 }

	static class ViewHolder {

		public TextView text;
		public ImageView image;
	}
}
